package com.kd.juhaowan.ui.holder;

import android.annotation.SuppressLint;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;


import com.kd.juhaowan.R;
import com.kd.juhaowan.http.model.GameDjqModel;
import com.kd.juhaowan.ui.adapter.BaseViewHolder;
import com.kd.juhaowan.ui.listener.OnItemClickListener;
import com.kd.juhaowan.ui.listener.OnItemDianzanListener;

import butterknife.BindView;
import butterknife.OnClick;

public class MineDjqViewHolder extends BaseViewHolder {




    @BindView(R.id.item_name)
    TextView nameView;


    @BindView(R.id.item_content)
    TextView contentView;
    @BindView(R.id.item_time)
    TextView timeView;

    @BindView(R.id.item_lingqu)
    TextView lingquView;
    @BindView(R.id.item_diver)
    View diverView;

    private GameDjqModel mModel;

    @OnClick(R.id.item_lingqu)
    public void onLingquclick(){
        if(mModel.getIs_receive()!=0)
            return;
        OnItemClickListener listener = getOnItemClickListener();
        if(listener instanceof OnItemDianzanListener){
            ((OnItemDianzanListener) listener).onItemDianzanClick(this,getLayoutPosition());
        }
    }

    public MineDjqViewHolder(@NonNull View itemView) {
        super(itemView);
    }



    @SuppressLint("ResourceType")
    public void setDate(GameDjqModel model,boolean isLast){
        mModel = model;
        diverView.setVisibility(isLast?View.INVISIBLE:View.VISIBLE);
        nameView.setText(model.getGame_name()+"-"+model.getVoucher_name());
        contentView.setText(model.getContent());
        timeView.setText("有效期至"+model.getUsage_end_time());

        if(model.getIs_receive()==0){
            lingquView.setText("去使用");
            lingquView.setTextColor(getContext().getColor(R.color.white));
            lingquView.setBackgroundResource(R.drawable.login_small_btn);
        }else if(model.getIs_receive()==1){
            lingquView.setText("已使用");
            lingquView.setTextColor(getContext().getColor(R.color.c60));
            lingquView.setBackgroundResource(R.drawable.gift_btn_recived);
        }else {
            lingquView.setText("已过期");
            lingquView.setTextColor(getContext().getColor(R.color.cc8));
            lingquView.setBackgroundResource(R.drawable.f7_13_bg);
        }
    }



}
